﻿using System.Linq;
using Enyim.Caching;
using Ayatta.Contract;
using Newtonsoft.Json;
using System.Web.Mvc;
using Web.Item.Models;
using Web.Base.Controllers;

namespace Web.Item.Controllers
{
    public class HomeController : BaseController
    {
        public HomeController(ILogService logService, IBaseService baseService, IExtraService extraService, IStoreService storeService, IOrderService orderService, IGameService gameService, IAuctionService auctionService, IPassportService passportService, IPaymentService paymentService, IMemcachedClient memcachedClient)
            : base(logService, baseService, extraService, storeService, orderService, gameService, auctionService, passportService, paymentService, memcachedClient)
        {
        }

        public ActionResult Index(int param = 0)
        {
            var model = new HomeControllerModel.Index();
            var item = StoreService.GetProductItem(param);
            model.Item = item;
            if (item.Skus != null && item.Skus.Count > 0)
            {
                var skus = item.Skus.ToDictionary(o => o.Properties, o => new { id = o.Id, itemId = o.ItemId, price = o.Price, count = o.Quantity });
                model.SkusJson = JsonConvert.SerializeObject(skus);
            }
            else
            {
                model.SkusJson = "{}";
            }
            return View(model);
        }
    }
}
